package com.sun.hunk.hibernate.domain.impl;

import com.sun.hunk.hibernate.domain.Item;
import com.sun.hunk.hibernate.domain.Comment;
import com.sun.hunk.hibernate.domain.User;
import com.sun.hunk.util.DateUtil;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author abhi
 */
@Entity
@Table(name = "comment")
public class CommentImpl implements Comment {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Long id;
    @Lob
    @Column(name = "description")
    private String description;
    @Column(name = "created_on")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createdOn;
    @JoinColumn(name = "topic_id", referencedColumnName = "id")
    @ManyToOne(optional = false,targetEntity=ItemImpl.class)
    private Item item;
    @JoinColumn(name = "user_id", referencedColumnName = "id")
    @OneToOne(targetEntity=UserImpl.class)
    private User user;

    public CommentImpl() {
        createdOn = new Date();
    }

    public CommentImpl(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Date getCreatedOn() {
        return createdOn;
    }
    public String getCreatedOnFormatted() {
        return DateUtil.formatToString(createdOn, DateUtil.Format.DD_MMM_yy);
    }

    public void setCreatedOn(Date createdOn) {
        this.createdOn = createdOn;
    }

    public Item getItem() {
        return item;
    }

    public void setItem(Item item) {
        this.item = item;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }


    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof CommentImpl)) {
            return false;
        }
        CommentImpl other = (CommentImpl) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.sun.hunk.hibernate.domain.Comment[id=" + id + "]";
    }

}
